package com.hhh.demo.sx.resolve;

import com.hhh.demo.sx.exception.MyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 统一异常处理类
 *
 * @author lenovo
 * @create 2022/1/3 8:59
 */
@ControllerAdvice
public class MyExceptionResolve {

    @ExceptionHandler(value = Exception.class)
    public ResponseEntity<Object> exceptionHandler1() {
        return new ResponseEntity<>("内部处理错误，请稍后再试",HttpStatus.INTERNAL_SERVER_ERROR);
    }

    @ExceptionHandler(value = MyException.class)
    public ResponseEntity<Object> exceptionHandler2(MyException e) {

        return new ResponseEntity<>(e.getMsg(),HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
